(function () {
    'use strict';

    angular
        .module('app.Diagnosis')
        .controller('DiagnosisController', DiagnosisController);

    DiagnosisController.$inject = ['logger', '$state', '$rootScope', '$mdDialog','DiagnosisProvider'];
    /* @ngInject */
    function DiagnosisController(logger, $state, $rootScope, $mdDialog, DiagnosisProvider) {
        var vm = this;
        vm.title = 'Diagnosis';
        vm.CloseDialog = CloseDialog;
        vm.onPaginate = onPaginate;
        vm.SelectedCodes = [];
        vm.TotalDiagnosis = 1000;
        activate();

        function activate() {
            logger.info('Activated Diagnosis View');
            //var promise = DiagnosisProvider.GetPatientDiagnosis(vm.ReferralID).then(function (response) {
            //    if (response.data.ErrorMessage != 'No Data') {
            //        vm.TotalDiagnosis = DiagnosisProvider.SetAllDiagnosisList(response.data.PatientDiagnosis);
            //        vm.DiagnosisCodes = DiagnosisProvider.GetDiagnosisListForPage(0, 10);
            //        vm.SelectedCodes = response.data.ChipData;
            //        $mdDialog.hide();
            //    }
            //});
            vm.DiagnosisCodes = [{ "PatientID": "10322", "DiagnosisID": "25327", "ICD10Code": "R22.9", "LongDescription": "Localized swelling mass and lump unspecified", "ChipItem": "Localized swelling mass and lump unspecified (R22.9)" }
                , { "PatientID": "10322", "DiagnosisID": "42657", "ICD10Code": "Z68.32", "LongDescription": "Body mass index [BMI] 32.0-32.9 adult", "ChipItem": "Body mass index [BMI] 32.0-32.9 adult (Z68.32)" }
                , { "PatientID": "0", "DiagnosisID": "22", "ICD10Code": "A04.4", "LongDescription": "Other intestinal Escherichia coli infections", "ChipItem": "Other intestinal Escherichia coli infections (A04.4)" }
                , { "PatientID": "0", "DiagnosisID": "24", "ICD10Code": "A04.8", "LongDescription": "Other specified bacterial intestinal infections", "ChipItem": "Other specified bacterial intestinal infections (A04.8)" }
                , { "PatientID": "0", "DiagnosisID": "40", "ICD10Code": "A07.9", "LongDescription": "Protozoal intestinal disease unspecified", "ChipItem": "Protozoal intestinal disease unspecified (A07.9)" }
                , { "PatientID": "0", "DiagnosisID": "46", "ICD10Code": "A08.8", "LongDescription": "Other specified intestinal infections", "ChipItem": "Other specified intestinal infections (A08.8)" }
                , { "PatientID": "0", "DiagnosisID": "87", "ICD10Code": "A22.2", "LongDescription": "Gastrointestinal anthrax", "ChipItem": "Gastrointestinal anthrax (A22.2)" }]
            vm.SelectedCodes = ["Localized swelling mass and lump unspecified (R22.9)"];
        }

        function CloseDialog(FormDirty) {
            if (FormDirty) {
                $mdDialog.show({
                    controller: 'ConfirmController',
                    skipHide: true,
                    templateUrl: 'app/layout/ModalConfirm.html',
                    parent: angular.element(document.body),
                    controllerAs: 'vm',
                    clickOutsideToClose: false,
                    escapeToClose: false,
                    locals: {
                        ModalTitle: 'Confirm'
                        , ModalText: 'Changes have not been saved. Are you sure you want to cancel?'
                        , NoButtonText: 'No'
                        , YesButtonText: ' Yes'
                    }
                })
                .then(
                    //Yes Function
                    function () {
                        $mdDialog.cancel();
                    }

                    //No Function 
                    , function () {
                        //Do Nothing.
                    }
                );
            }
            else {
                $mdDialog.cancel();
            }
        }

        function onPaginate(page, limit) {
            vm.DiagnosisCodes = DiagnosisProvider.GetDiagnosisListForPage(page - 1, limit);
        }
    }
})();
